/*
 * Copyright 2010 Askar Kalykov, oxygene.core@gmail.com
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.oxygenecore.processor.statement;

import com.oxygenecore.processor.ExecutionContext;
import com.oxygenecore.processor.Statement;
import com.oxygenecore.processor.StatementException;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Askar Kalykov
 *         Date: 11.09.2010
 *         Time: 18:01:59
 */
public class CompositeStatement implements Statement {

    private List<Statement> statements = new LinkedList<Statement>();

    public CompositeStatement(List<Statement> statements) {
        for (Statement statement : statements) {
            if (statement == null){
                throw new NullPointerException("one of statements");
            }
            this.statements.add(statement);
        }
    }

    public void addStatement(Statement statement){
        if (statement == null) {
            throw new NullPointerException("statement");
        }
        statements.add(statement);
    }


    public void execute(ExecutionContext executionContext) throws StatementException {
        assert executionContext != null;
        for (Statement statement : statements) {
            statement.execute(executionContext);
        }
    }
}
